<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/8/14
 * Time: 15:05
 */

namespace App\Http\Controllers\Web;


use App\Service\MemberService;
use Illuminate\Http\Response;

class MemberController extends BaseController
{
    public function index()
    {
        $params = $this->request->post();
        $page = $this->request->post('page',1);
        $limit = $this->request->post('limit',10);
        return MemberService::getList($params,'id','DESC',$page,$limit);
    }

    public function getMemberById()
    {
        $memberId = $this->request->post('id');
        if(!$memberId){
            return Response()->json(['code'=>201,'参数缺失']);
        }
        return MemberService::getMemberById($memberId);
    }

    public function edit()
    {
        $params = $this->request->post();
        if(!isset($params['id']) || empty(intval($params['id']))){
            return Response()->json(['code'=>201,'msg'=>'参数缺失']);
        }
        return MemberService::edit($params);
    }

    public function destroy()
    {
        $ids = $this->request->post('ids');
        $ids = is_array($ids) ? $ids : [$ids];
        if(!$ids){
            return Response()->json(['code'=>201,'msg'=>'请选择要删除的会员']);
        }
        return MemberService::destroy($ids);

    }

}
